﻿using System;
using System.Collections;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using OpenTK.Input;

namespace Kepler
{
    abstract class OrbitalSystem : GravityObject
    {
        public ArrayList children = new ArrayList(); //Objects within the system, each will orbit their parent

        public void add(GravityObject child)
        {
            children.Add(child);
        }

        public void tick()
        {
            for (int i = 0; i < children.Count; i++)
            {
                GravityObject current = (GravityObject)children[i];

                current.degreeInOrbit = (current.degreeInOrbit - current.orbitalVelocity);
                current.position.X = this.position.X + (float)(Math.Cos(current.degreeInOrbit / 180 * Math.PI) * current.distanceFromParent);
                current.position.Y = this.position.Y + (float)(Math.Sin(current.degreeInOrbit / 180 * Math.PI) * current.distanceFromParent);

                if (current is OrbitalSystem)
                {
                    ((OrbitalSystem)current).tick();

                    /*
                    for (int j = 0; j < ((OrbitalSystem)current).children.Count; j++)
                    {
                        GravityObject subitem = (GravityObject)((OrbitalSystem)current).children[j];
                        subitem.setDegreeInOrbit(subitem.degreeInOrbit - 1.0f);
                        subitem.position.X = current.position.X + (float)(Math.Cos(subitem.degreeInOrbit / 180.0f * Math.PI) * subitem.distanceFromParent);
                        subitem.position.Y = current.position.Y + (float)(Math.Sin(subitem.degreeInOrbit / 180.0f * Math.PI) * subitem.distanceFromParent);
                    }
                    */
                     
                }
            }
        }
    }
}
